<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">订单ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="id" autocomplete="off" class="layui-input">
                            </div>
                        </div>
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">商品名称</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="name" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-inline">
                            <label class="layui-form-label">供应商</label>
                            <div class="layui-input-inline">
                                <input type="text" name="supplier" autocomplete="off" class="layui-input" placeholder="请输入供应商完整名称">
                            </div>
                        </div>
<!--                        <div class="layui-inline">-->
<!--                            <label class="layui-form-label">用户角色</label>-->
<!--                            <div class="layui-input-inline">-->
<!--                                <input type="text" name="role" autocomplete="off" class="layui-input">-->
<!--                            </div>-->
<!--                        </div>-->
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="orderList">查看</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-warm layui-btn-xs data-count-edit" lay-event="verify">审核</a>
<!--            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="toBuy">转采购</a>-->
        </script>

    </div>
</div>
<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js?v=1.0.4}" charset="utf-8"></script>
<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/purchase/orderInfo',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],

            cols: [
                [
                    {type: 'checkbox', width: 50},
                    {field: 'id', width: 180, title: '订单编号', sort: true},
                    // {field: 'goodsName', width: 100, title: '名称', templet: '<div>{{d.orderLIstVos.OrderLIstVo.goodsName}}</div>' },
                    {field: 'allGoodsName', width: 150, title: '名称'},
                    {field: 'origin', width: 130, title: '供应商'},
                    {field: 'account', width: 130, title: '付款账户'},
                    {field: 'moneyAmount', width: 180, title: '总金额'},
                    {field: 'createTime', title: '创建时间', width: 180, sort: true},
                    {field: 'remark', minWidth: 200, title: '备注'},
                    {field: 'handsPerson', width: 100, title: '经办人'},
                    {field: 'status', width: 100, title: '状态', sort: true},
                    {title: '操作', minWidth: 80, toolbar: '#currentTableBar', align: "center"}
                ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加商品',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/purchase/getAddOrderPage',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                $.ajax({
                    type: "POST",
                    url: "/purchase/delAllOrder",
                    contentType: "application/json;charset=utf-8",
                    data: JSON.stringify(data),
                    beforeSend: function() {
                        layer.msg("正在处理...")
                    },
                    success: function (data) {
                        if (data.code == 500) {
                            layer.msg(data.message);
                        } else {
                            layer.msg(data.message);
                            function send() {
                                // var iframeIndex = parent.layer.getFrameIndex(window.name);
                                window.location.reload();
                                // parent.layer.close(iframeIndex);
                            }
                            setTimeout(send,1000);

                        }
                    },
                    error: function (data) {
                        layer.msg("删除失败！");
                    }
                });
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'orderList') {

                var index = layer.open({
                    title: '订单商品详情信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/purchase/getOrderListPage?id='+data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }else if (obj.event === 'edit') {
                $.ajax({
                    type: "post",
                    url: '/purchase/confirmOrderStatus?id='+data.id,
                    // data: data.id,
                    beforeSend: function() {
                        layer.msg("正在处理...")
                    },
                    success: function (d) {
                        if (d.code == 500) {
                            layer.msg(d.message);
                        } else {
                            var index = layer.open({
                                    title: '编辑商品订单',
                                    type: 2,
                                    shade: 0.2,
                                    maxmin:true,
                                    shadeClose: true,
                                    area: ['100%', '100%'],
                                    content: '/purchase/getEditOrderPage?id='+data.id,
                                });
                                $(window).on("resize", function () {
                                    layer.full(index);
                                });
                                return false;
                        }
                    },
                    error: function (data) {
                        layer.msg("服务器异常QAQ！");
                    }
                })

                // var index = layer.open({
                //     title: '编辑商品订单',
                //     type: 2,
                //     shade: 0.2,
                //     maxmin:true,
                //     shadeClose: true,
                //     area: ['100%', '100%'],
                //     content: '/purchase/getEditOrderPage?id='+data.id,
                // });
                // $(window).on("resize", function () {
                //     layer.full(index);
                // });
                // return false;
            } else if (obj.event === 'verify') {
                layer.confirm('您确认订单信息无误，将商品审核转入采购吗？', function (index) {
                    $.ajax({
                        type: "post",
                        url: "/purchase/verifyOrder?id=" + data.id,
                        // data: data.id,
                        beforeSend: function() {
                            layer.msg("正在处理...")
                        },
                        success: function (data) {
                            if (data.code == 500) {
                                layer.msg(data.message);
                            } else {
                                layer.msg(data.message);

                                function send() {
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    window.location.reload();
                                    // obj.del();
                                    parent.layer.close(iframeIndex);
                                }
                                setTimeout(send,1500);

                            }
                        },
                        error: function (data) {
                            layer.msg("审核失败！");
                        }
                    })
                });
            }
        });

    });

</script>

</body>
</html>